package com.talktalk.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class JdbcUtils {

	public static Connection getConnection() {
		try {
			Class.forName("com.mysql.jdbc.Driver");
			return DriverManager
					.getConnection(
							"jdbc:mysql://localhost:3306/myicq?rewriteBatchedStatements=true",
							"root", "1234");

		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}

	public static void closeConnection(Connection conn, ResultSet rs,
			PreparedStatement pstmt) {

		try {
			if (conn != null) {
				conn.close();
			}
			if(rs!=null){
				rs.close();
			}
			if(pstmt!=null){
				pstmt.close();
			}
		} catch (SQLException e) {
			throw new RuntimeException(e);
		}
	}

}
